<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - ged.info - detail/lcast_precision.hpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../index.html">directory</a> - <a href="index.html">detail</a> - lcast_precision.hpp</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>ged.info</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2009-06-09</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">7</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">0.0 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">0</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : // Copyright Alexander Nasonov &amp; Paul A. Bristow 2006.
<span class="lineNum">       2 </span>                : 
<span class="lineNum">       3 </span>                : // Use, modification and distribution are subject to the
<span class="lineNum">       4 </span>                : // Boost Software License, Version 1.0.
<span class="lineNum">       5 </span>                : // (See accompanying file LICENSE_1_0.txt
<span class="lineNum">       6 </span>                : // or copy at http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       7 </span>                : 
<span class="lineNum">       8 </span>                : #ifndef BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
<span class="lineNum">       9 </span>                : #define BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
<span class="lineNum">      10 </span>                : 
<span class="lineNum">      11 </span>                : #include &lt;climits&gt;
<span class="lineNum">      12 </span>                : #include &lt;ios&gt;
<span class="lineNum">      13 </span>                : #include &lt;limits&gt;
<span class="lineNum">      14 </span>                : 
<span class="lineNum">      15 </span>                : #include &lt;boost/config.hpp&gt;
<span class="lineNum">      16 </span>                : #include &lt;boost/integer_traits.hpp&gt;
<span class="lineNum">      17 </span>                : 
<span class="lineNum">      18 </span>                : #ifndef BOOST_NO_IS_ABSTRACT
<span class="lineNum">      19 </span>                : // Fix for SF:1358600 - lexical_cast &amp; pure virtual functions &amp; VC 8 STL
<span class="lineNum">      20 </span>                : #include &lt;boost/mpl/if.hpp&gt;
<span class="lineNum">      21 </span>                : #include &lt;boost/type_traits/is_abstract.hpp&gt;
<span class="lineNum">      22 </span>                : #endif
<span class="lineNum">      23 </span>                : 
<span class="lineNum">      24 </span>                : #if defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || \
<span class="lineNum">      25 </span>                :   (defined(BOOST_MSVC) &amp;&amp; (BOOST_MSVC&lt;1310))
<span class="lineNum">      26 </span>                : 
<span class="lineNum">      27 </span>                : #define BOOST_LCAST_NO_COMPILE_TIME_PRECISION
<span class="lineNum">      28 </span>                : #endif
<span class="lineNum">      29 </span>                : 
<span class="lineNum">      30 </span>                : #ifdef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
<span class="lineNum">      31 </span>                : #include &lt;boost/assert.hpp&gt;
<span class="lineNum">      32 </span>                : #else
<span class="lineNum">      33 </span>                : #include &lt;boost/static_assert.hpp&gt;
<span class="lineNum">      34 </span>                : #endif
<span class="lineNum">      35 </span>                : 
<span class="lineNum">      36 </span>                : namespace boost { namespace detail {
<span class="lineNum">      37 </span>                : 
<span class="lineNum">      38 </span>                : class lcast_abstract_stub {};
<span class="lineNum">      39 </span>                : 
<span class="lineNum">      40 </span>                : #ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
<span class="lineNum">      41 </span>                : // Calculate an argument to pass to std::ios_base::precision from
<span class="lineNum">      42 </span>                : // lexical_cast. See alternative implementation for broken standard
<span class="lineNum">      43 </span>                : // libraries in lcast_get_precision below. Keep them in sync, please.
<span class="lineNum">      44 </span>                : template&lt;class T&gt;
<span class="lineNum">      45 </span>                : struct lcast_precision
<span class="lineNum">      46 </span>                : {
<span class="lineNum">      47 </span>                : #ifdef BOOST_NO_IS_ABSTRACT
<span class="lineNum">      48 </span>                :     typedef std::numeric_limits&lt;T&gt; limits; // No fix for SF:1358600.
<span class="lineNum">      49 </span>                : #else
<span class="lineNum">      50 </span>                :     typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_&lt;
<span class="lineNum">      51 </span>                :         boost::is_abstract&lt;T&gt;
<span class="lineNum">      52 </span>                :       , std::numeric_limits&lt;lcast_abstract_stub&gt;
<span class="lineNum">      53 </span>                :       , std::numeric_limits&lt;T&gt;
<span class="lineNum">      54 </span>                :       &gt;::type limits;
<span class="lineNum">      55 </span>                : #endif
<span class="lineNum">      56 </span>                : 
<span class="lineNum">      57 </span>                :     BOOST_STATIC_CONSTANT(bool, use_default_precision =
<span class="lineNum">      58 </span>                :             !limits::is_specialized || limits::is_exact
<span class="lineNum">      59 </span>                :         );
<span class="lineNum">      60 </span>                : 
<span class="lineNum">      61 </span>                :     BOOST_STATIC_CONSTANT(bool, is_specialized_bin =
<span class="lineNum">      62 </span>                :             !use_default_precision &amp;&amp;
<span class="lineNum">      63 </span>                :             limits::radix == 2 &amp;&amp; limits::digits &gt; 0
<span class="lineNum">      64 </span>                :         );
<span class="lineNum">      65 </span>                : 
<span class="lineNum">      66 </span>                :     BOOST_STATIC_CONSTANT(bool, is_specialized_dec =
<span class="lineNum">      67 </span>                :             !use_default_precision &amp;&amp;
<span class="lineNum">      68 </span>                :             limits::radix == 10 &amp;&amp; limits::digits10 &gt; 0
<span class="lineNum">      69 </span>                :         );
<span class="lineNum">      70 </span>                : 
<span class="lineNum">      71 </span>                :     BOOST_STATIC_CONSTANT(std::streamsize, streamsize_max =
<span class="lineNum">      72 </span>                :             boost::integer_traits&lt;std::streamsize&gt;::const_max
<span class="lineNum">      73 </span>                :         );
<span class="lineNum">      74 </span>                : 
<span class="lineNum">      75 </span>                :     BOOST_STATIC_CONSTANT(unsigned int, precision_dec = limits::digits10 + 1U);
<span class="lineNum">      76 </span>                : 
<span class="lineNum">      77 </span>                :     BOOST_STATIC_ASSERT(!is_specialized_dec ||
<span class="lineNum">      78 </span>                :             precision_dec &lt;= streamsize_max + 0UL
<span class="lineNum">      79 </span>                :         );
<span class="lineNum">      80 </span>                : 
<span class="lineNum">      81 </span>                :     BOOST_STATIC_CONSTANT(unsigned long, precision_bin =
<span class="lineNum">      82 </span>                :             2UL + limits::digits * 30103UL / 100000UL
<span class="lineNum">      83 </span>                :         );
<span class="lineNum">      84 </span>                : 
<span class="lineNum">      85 </span>                :     BOOST_STATIC_ASSERT(!is_specialized_bin ||
<span class="lineNum">      86 </span>                :             (limits::digits + 0UL &lt; ULONG_MAX / 30103UL &amp;&amp;
<span class="lineNum">      87 </span>                :             precision_bin &gt; limits::digits10 + 0UL &amp;&amp;
<span class="lineNum">      88 </span>                :             precision_bin &lt;= streamsize_max + 0UL)
<span class="lineNum">      89 </span>                :         );
<span class="lineNum">      90 </span>                : 
<span class="lineNum">      91 </span>                :     BOOST_STATIC_CONSTANT(std::streamsize, value =
<span class="lineNum">      92 </span>                :             is_specialized_bin ? precision_bin
<span class="lineNum">      93 </span>                :                                : is_specialized_dec ? precision_dec : 6
<span class="lineNum">      94 </span>                :         );
<span class="lineNum">      95 </span>                : };
<span class="lineNum">      96 </span>                : #endif
<span class="lineNum">      97 </span>                : 
<span class="lineNum">      98 </span>                : template&lt;class T&gt;
<span class="lineNum">      99 </span><span class="lineNoCov">              0 : inline std::streamsize lcast_get_precision(T* = 0)</span>
<span class="lineNum">     100 </span>                : {
<span class="lineNum">     101 </span>                : #ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
<span class="lineNum">     102 </span><span class="lineNoCov">              0 :     return lcast_precision&lt;T&gt;::value;</span>
<span class="lineNum">     103 </span>                : #else // Follow lcast_precision algorithm at run-time:
<span class="lineNum">     104 </span>                : 
<span class="lineNum">     105 </span>                : #ifdef BOOST_NO_IS_ABSTRACT
<span class="lineNum">     106 </span>                :     typedef std::numeric_limits&lt;T&gt; limits; // No fix for SF:1358600.
<span class="lineNum">     107 </span>                : #else
<span class="lineNum">     108 </span>                :     typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_&lt;
<span class="lineNum">     109 </span>                :         boost::is_abstract&lt;T&gt;
<span class="lineNum">     110 </span>                :       , std::numeric_limits&lt;lcast_abstract_stub&gt;
<span class="lineNum">     111 </span>                :       , std::numeric_limits&lt;T&gt;
<span class="lineNum">     112 </span>                :       &gt;::type limits;
<span class="lineNum">     113 </span>                : #endif
<span class="lineNum">     114 </span>                : 
<span class="lineNum">     115 </span>                :     bool const use_default_precision =
<span class="lineNum">     116 </span>                :         !limits::is_specialized || limits::is_exact;
<span class="lineNum">     117 </span>                : 
<span class="lineNum">     118 </span>                :     if(!use_default_precision)
<span class="lineNum">     119 </span>                :     { // Includes all built-in floating-point types, float, double ...
<span class="lineNum">     120 </span>                :       // and UDT types for which digits (significand bits) is defined (not zero)
<span class="lineNum">     121 </span>                : 
<span class="lineNum">     122 </span>                :         bool const is_specialized_bin =
<span class="lineNum">     123 </span>                :             limits::radix == 2 &amp;&amp; limits::digits &gt; 0;
<span class="lineNum">     124 </span>                :         bool const is_specialized_dec =
<span class="lineNum">     125 </span>                :             limits::radix == 10 &amp;&amp; limits::digits10 &gt; 0;
<span class="lineNum">     126 </span>                :         std::streamsize const streamsize_max =
<span class="lineNum">     127 </span>                :             (boost::integer_traits&lt;std::streamsize&gt;::max)();
<span class="lineNum">     128 </span>                : 
<span class="lineNum">     129 </span>                :         if(is_specialized_bin)
<span class="lineNum">     130 </span>                :         { // Floating-point types with
<span class="lineNum">     131 </span>                :           // limits::digits defined by the specialization.
<span class="lineNum">     132 </span>                : 
<span class="lineNum">     133 </span>                :             unsigned long const digits = limits::digits;
<span class="lineNum">     134 </span>                :             unsigned long const precision = 2UL + digits * 30103UL / 100000UL;
<span class="lineNum">     135 </span>                :             // unsigned long is selected because it is at least 32-bits
<span class="lineNum">     136 </span>                :             // and thus ULONG_MAX / 30103UL is big enough for all types.
<span class="lineNum">     137 </span>                :             BOOST_ASSERT(
<span class="lineNum">     138 </span>                :                     digits &lt; ULONG_MAX / 30103UL &amp;&amp;
<span class="lineNum">     139 </span>                :                     precision &gt; limits::digits10 + 0UL &amp;&amp;
<span class="lineNum">     140 </span>                :                     precision &lt;= streamsize_max + 0UL
<span class="lineNum">     141 </span>                :                 );
<span class="lineNum">     142 </span>                :             return precision;
<span class="lineNum">     143 </span>                :         }
<span class="lineNum">     144 </span>                :         else if(is_specialized_dec)
<span class="lineNum">     145 </span>                :         {   // Decimal Floating-point type, most likely a User Defined Type
<span class="lineNum">     146 </span>                :             // rather than a real floating-point hardware type.
<span class="lineNum">     147 </span>                :             unsigned int const precision = limits::digits10 + 1U;
<span class="lineNum">     148 </span>                :             BOOST_ASSERT(precision &lt;= streamsize_max + 0UL);
<span class="lineNum">     149 </span>                :             return precision;
<span class="lineNum">     150 </span>                :         }
<span class="lineNum">     151 </span>                :     }
<span class="lineNum">     152 </span>                : 
<span class="lineNum">     153 </span>                :     // Integral type (for which precision has no effect)
<span class="lineNum">     154 </span>                :     // or type T for which limits is NOT specialized,
<span class="lineNum">     155 </span>                :     // so assume stream precision remains the default 6 decimal digits.
<span class="lineNum">     156 </span>                :     // Warning: if your User-defined Floating-point type T is NOT specialized,
<span class="lineNum">     157 </span>                :     // then you may lose accuracy by only using 6 decimal digits.
<span class="lineNum">     158 </span>                :     // To avoid this, you need to specialize T with either
<span class="lineNum">     159 </span>                :     // radix == 2 and digits == the number of significand bits,
<span class="lineNum">     160 </span>                :     // OR
<span class="lineNum">     161 </span>                :     // radix = 10 and digits10 == the number of decimal digits.
<span class="lineNum">     162 </span>                : 
<span class="lineNum">     163 </span>                :     return 6;
<span class="lineNum">     164 </span>                : #endif
<span class="lineNum">     165 </span>                : }
<span class="lineNum">     166 </span>                : 
<span class="lineNum">     167 </span>                : template&lt;class T&gt;
<span class="lineNum">     168 </span>                : inline void lcast_set_precision(std::ios_base&amp; stream, T*)
<span class="lineNum">     169 </span>                : {
<span class="lineNum">     170 </span>                :     stream.precision(lcast_get_precision&lt;T&gt;());
<span class="lineNum">     171 </span>                : }
<span class="lineNum">     172 </span>                : 
<span class="lineNum">     173 </span>                : template&lt;class Source, class Target&gt;
<span class="lineNum">     174 </span><span class="lineNoCov">              0 : inline void lcast_set_precision(std::ios_base&amp; stream, Source*, Target*)</span>
<span class="lineNum">     175 </span>                : {
<span class="lineNum">     176 </span><span class="lineNoCov">              0 :     std::streamsize const s = lcast_get_precision((Source*)0);</span>
<span class="lineNum">     177 </span><span class="lineNoCov">              0 :     std::streamsize const t = lcast_get_precision((Target*)0);</span>
<span class="lineNum">     178 </span><span class="lineNoCov">              0 :     stream.precision(s &gt; t ? s : t);</span>
<span class="lineNum">     179 </span><span class="lineNoCov">              0 : }</span>
<span class="lineNum">     180 </span>                : 
<span class="lineNum">     181 </span>                : }}
<span class="lineNum">     182 </span>                : 
<span class="lineNum">     183 </span>                : #endif //  BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
<span class="lineNum">     184 </span>                : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
